package com.git_taoxian.test3;

import java.io.*;
import java.net.Socket;

public class ClientTest {
    public static void main(String[] args) {
        try {
//        获取客户端Socket对象
            Socket socket = new Socket("127.0.0.1", 8090);
//        获取低级字节输出输入流对象
            OutputStream os = socket.getOutputStream();
            InputStream is = socket.getInputStream();
//        获取当前的磁盘文件并读取
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:/student.txt"));
            byte[] buf = new byte[1024];//每次读1k的数据量
            int len;
            while((len= bis.read(buf))!=-1){
                os.write(buf,0,len);
            }
//        关闭输出流
            socket.shutdownOutput();
//            获取服务器的反馈信息
            DataInputStream dis = new DataInputStream(is);
            System.out.println(dis.readUTF());
//        关闭资源
            bis.close();
            is.close();
            os.close();
            socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
